<?php
namespace App\Admin\Extensions\Tools;

use Encore\Admin\Grid\Tools\BatchAction;

class Examine extends BatchAction
{
    protected $action;

    public function __construct($action = 1)
    {
        $this->action = $action;
    }

    public function script()
    {
        return <<<EOT

        $('{$this->getElementClass()}').on('click', function() {
        
            $.ajax({
                method: 'post',
                url: '/admin/releaseAll',
                data: {
                    _token:LA.token,
                    ids: selectedRows(),
                    type: {$this->action}
                },
                success: function (res) {
                
                    res = jQuery.parseJSON(res);
                    if(res.state == 1){
                        swal(res.msg);
                        $.pjax.reload('#pjax-container');
                    }else{
                        swal(res.msg);
                    }       
                }
            });
        });

EOT;

    }
}